import { ConfigService } from '@nestjs/config'
import { RedisModuleOptions } from '@ttou/nest-redis'

import { REDIS_CLIENT, REDIS_CLIENT_OPTIONS } from '@/constants'
import { IConfig } from '@/interfaces'

export const REDIS_OPTIONS: RedisModuleOptions = {
  global: true,
  createType: 'client',
  clientToken: REDIS_CLIENT,
  optionsToken: REDIS_CLIENT_OPTIONS,
  optionsProvider: {
    useFactory: (configService: ConfigService) => {
      return configService.get<IConfig['redis']>('redis')
    },
    inject: [ConfigService]
  }
}
